package producer.impl;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import managment.impl.Managment;
import producer.bean.OrderInfo;
import producer.bean.ProductRequiredBean;
import producer.interfaces.IProducer;
import product.enums.Category;
import product.impl.Product;
import product.interfaces.IProduct;
@Data
@AllArgsConstructor
@NoArgsConstructor
/**
 * Komponent Producent
 * @author Witold Muszynski
 *
 */
public class Producer implements IProducer {

	private String name;
	private Category category;
	private Managment managment;
	private Map<String,ProductRequiredBean> products;
	private double price;
	private int produceTime;
	@Override
	public String getCompanyName() {
		return name;
	}

	@Override
	public Category getCategory() {
		return category;
	}

	/**
	 * Wycenia zamowienie dla produktu
	 */
	@Override
	public OrderInfo measuredOrder(String name, int count) {
		OrderInfo info = new OrderInfo();
		info.setCompanyName(getCompanyName());
		info.setName(name);
		info.setFinishDate(managment.measuredOrderDate(new Product(name,count,this.category)));
		info.setCost(count *price);
		return info;
	}
	/**
	 * Dodaje nowo kupiony produkt
	 */
	@Override
	public IProduct buyRequierdProduct(String name, int count,	Category category) {
		return new Product(name, count, category);
	}

	@Override
	public Product executeOrder(String name, int count) {
		Product product = new Product(name, count, this.category);
		managment.delegateProduce(product);
		return product;
		
	}
	
	/**
	 * Dodaje nowo zakupione produktu
	 * @param count
	 */
	public void addBuyProductCount(int count){
		this.managment.addBuyProductCount(count);
	}

	public void analyze() {
		for(String productName : products.keySet()){
			managment.analyze(productName,getCategory());
		}
			
	}

	/**
	 * Sprawdza czy jest produkt dostepny
	 */
	@Override
	public boolean isProductAvaible(Product product) {
		return managment.isProductAvaible(product);
	}
	/**
	 * Zwraca liste dostepnych produktow
	 * @return
	 */
	public List<String> getProductNames() {
		return new ArrayList<String>(products.keySet());
	}
	/**
	 * zwraca wymagane produktu do produkcji
	 * @param productName
	 * @return
	 */
	public  ProductRequiredBean getProductRequierd(String productName){
		return products.get(productName);
		
	}
}
